use std::sync::Arc;
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
use std::time::Duration;
pub async fn db_connect(host:&str,prot:&u16,pwd:&str,usernaem:&str)-> Result<Arc<DatabaseConnection>, sea_orm::DbErr> {
    let database = "ai_demo";
    let mut opt = ConnectOptions::new(format!("postgres://{}:{}@{}:{}/ai_demo?currentSchema={}",usernaem,pwd,host,prot,database));
    opt.max_connections(100)
        .min_connections(5)
        .connect_timeout(Duration::from_secs(8))
        .acquire_timeout(Duration::from_secs(8))
        .idle_timeout(Duration::from_secs(600))
        .max_lifetime(Duration::from_secs(3600))
        .sqlx_logging(true);
        // .sqlx_logging_level(log::LevelFilter::Info)
        // .set_schema_search_path(database);

    let db = Database::connect(opt).await?;
    Ok(Arc::new(db))
}